#!/bin/bash
function ClangFormatFile() {
	for file in `ls -a $1`
    do
        if [ -d $1"/"$file ]
        then
            if [[ $file != '.' && $file != '..' && $file != "build" ]]
			then
                ClangFormatFile $1"/"$file
            fi
        else
			if [ "${file##*.}"x = "h"x ] ||
				[ "${file##*.}"x = "cc"x ] ||
				[ "${file##*.}"x = "m"x ] || 
				[ "${file##*.}"x = "cu"x ] || [ "${file##*.}"x = "mm"x ]; then
				./clang-format -i $1'/'$file
				sed -i -e 's/[ ]*$//g' $1'/'$file
			fi
        fi
    done
}

echo '------clang-format start: '$1
ClangFormatFile $1
echo '------clang-format end'

